#include "GameObject.h"

GameObject::GameObject(void)
{
	_turnstep = .01f;
	mobile = NULL;
	renderable = NULL;
	parent = NULL;
	font = NULL;
}

GameObject::~GameObject(void)
{
	GlobalDebug::GetInstance()->DbgOut("Deleting a gameObject");

	messages.clear();
	if(mobile != NULL)
	{
		GlobalDebug::GetInstance()->DbgOut("about to delete mobile");
		delete mobile;
	}

	if(renderable != NULL)
	{
		GlobalDebug::GetInstance()->DbgOut("about to delete Renderable");
		delete renderable;
	}
}

int GameObject::GetID(){

	return this->_ID;
}

void GameObject::SetID(int id){

	this->_ID = id;
}

void GameObject::SetMobile(Mobile* value)
{
	assert(value != NULL);
	mobile = value;
	mobile->SetOwner(this);		
}

Mobile* GameObject::GetMobile()
{
	return mobile;
}

bool GameObject::CollidesWith(GameObject* obj){
	return false;

}

void GameObject::KillSlowly()
{
	if(_lifeTime > 0)
		_lifeTime--;
}

void GameObject::SetLifetime(int lifetime)
{
	this->_lifeTime = lifetime;
}

bool GameObject::IsDead()
{
	return this->_lifeTime == 0;
}

void GameObject::SendMessage(Message* msg)
{
	this->messages.push_back(msg);
}

void GameObject::ProcessMessages()
{
	PreProcessMessages();

	list<Message*>::iterator msgIter;	
	while(messages.size() > 0)
	{
		Message* message = messages.front();
		messages.pop_front();
		ProcessMessage(message);
	}
	
	PostProcessMessages();
}

void GameObject::SetController(Controller* owningController)
{
	this->owningController = owningController;
}

void GameObject::SetRenderable(IRenderable* value)
{
	renderable = value;
}

IRenderable* GameObject::GetRenderable()
{
	PreGetRenderable();
	return this->renderable;
}

GameObject* GameObject::GetParent()
{
	return parent;

}
void GameObject::SetParent(GameObject* value)
{
	parent = value;
}

int GameObject::GetDamage()
{
	return damage;

}

void GameObject::SetDamage(int value)
{
	damage = value;
}

void GameObject::SetFont(LPD3DXFONT font)
{
	this->font = font;
}